package cn.secuber.weing.ui.activity;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import cn.secuber.weing.R;
import io.rong.imkit.utilities.OptionsPopupDialog;
import io.rong.imlib.RongIMClient;

public class AboutRongCloudActivity extends BaseActivity {

    private boolean isHasNewVersion;
    private ImageView mNewVersionView;
    private String url;
    long[] mHits = new long[5];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        setTitle(R.string.set_rongcloud);

        RelativeLayout mUpdateLog = (RelativeLayout) findViewById(R.id.rl_update_log);
        RelativeLayout mFunctionIntroduce = (RelativeLayout) findViewById(R.id.rl_function_introduce);
        RelativeLayout mRongCloudWeb = (RelativeLayout) findViewById(R.id.rl_rongcloud_web);
        mNewVersionView = (ImageView) findViewById(R.id.about_sealtalk_version);

        RelativeLayout mVersionItem = (RelativeLayout) findViewById(R.id.rl_version);
        TextView version = (TextView) findViewById(R.id.sealtalk_version);

        version.setText("1.0");
        mUpdateLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //startActivity(new Intent(AboutRongCloudActivity.this, UpdateLogActivity.class));

                //Toast.makeText(AboutRongCloudActivity.this,"当前版本为测试版",Toast.LENGTH_SHORT).show();
            }
        });
        mFunctionIntroduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(AboutRongCloudActivity.this, FunctionIntroducedActivity.class));
            }
        });

        mRongCloudWeb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(AboutRongCloudActivity.this, RongWebActivity.class));
            }
        });
//        url = getIntent().getStringExtra("url");
//        isHasNewVersion = getIntent().getBooleanExtra("isHasNewVersion", false);
//        if (isHasNewVersion) {
//            mNewVersionView.setVisibility(View.VISIBLE);
//            mVersionItem.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    mNewVersionView.setVisibility(View.GONE);
//                    final AlertDialog dlg = new AlertDialog.Builder(AboutRongCloudActivity.this).create();
//                    dlg.show();
//                    Window window = dlg.getWindow();
//                    window.setContentView(R.layout.dialog_download);
//                    TextView text = (TextView) window.findViewById(R.id.friendship_content1);
//                    TextView photo = (TextView) window.findViewById(R.id.friendship_content2);
//                    text.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            Intent intent = new Intent();
//                            intent.setAction("android.intent.action.VIEW");
//                            Uri content_url = Uri.parse(url);
//                            intent.setData(content_url);
//                            startActivity(intent);
//                            dlg.cancel();
//                        }
//                    });
//                    photo.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            NToast.shortToast(mContext, getString(R.string.downloading_apk));
//                            UpdateService.Builder.create(url)
//                                    .setStoreDir("update/flag")
//                                    .setDownloadSuccessNotificationFlag(Notification.DEFAULT_ALL)
//                                    .setDownloadErrorNotificationFlag(Notification.DEFAULT_ALL)
//                                    .build(mContext);
//                            dlg.cancel();
//                        }
//                    });
//                    isHasNewVersion = false;
//                }
//            });
//        }




    }


    private void showOnlineStatusDialog() {
        String[] items = new String[2];

        items[0] = getString(R.string.ipad_online);
        items[1] = getString(R.string.imac_online);
        OptionsPopupDialog.newInstance(this, items).setOptionsPopupDialogListener(new OptionsPopupDialog.OnOptionsItemClickedListener() {
            @Override
            public void onOptionsItemClicked(int which) {
                if (which == 0) {
                    RongIMClient.getInstance().setUserOnlineStatus(5, null);
                } else if (which == 1) {
                    RongIMClient.getInstance().setUserOnlineStatus(6, null);
                }
            }
        }).show();

    }

    private String[] getVersionInfo() {
        String[] version = new String[2];

        PackageManager packageManager = getPackageManager();

        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0);
            version[0] = String.valueOf(packageInfo.versionCode);
            version[1] = packageInfo.versionName;
            return version;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return version;
    }
}
